package com.neuedu.qian.controller;

import com.neuedu.qian.vo.PageData;
import com.neuedu.qian.vo.ResponseData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.neuedu.qian.entity.Student;
import com.neuedu.qian.service.IStudentService;

/**
* Author lu
* Date   2025-07-31 09:49:29
*/
@Log4j2
@RequestMapping("/qian/api/student")
@RestController
@Tag(name = "学生控制器")
public class StudentController{

    @Autowired
    @Qualifier("studentService")
    private IStudentService studentService;

    /**
     * 分页查询学生
     * @param current 当前页号(默认为1)
     * @param size 每页显示记录条数(默认10)
     * @param keyword 关键字
     * @param stu 其它条件
     * @return
     */
    @GetMapping("/pageList")
    @Operation(summary = "分页查询学生")
    @Parameters({
            @Parameter(name = "current",description = "当前页号",required = true),
            @Parameter(name = "size",description = "每页显示记录条数",required = true),
            @Parameter(name = "keyword",description = "关键字",required = false),
            @Parameter(name = "gender",description = "性别(1:男;2:女)",required = false),
            @Parameter(name="status",description = "状态(1:正常;2:休学;3:退学;4:毕业)",required = false)
    })
   public ResponseData  queryPage(@RequestParam(defaultValue = "1",required = true) int current,@RequestParam(defaultValue = "10",required = true) int size,@Parameter(hidden = true) String keyword,@Parameter(hidden = true) Student stu){
       PageData<Student> page=studentService.queryPageList(current,size,keyword,stu);
       return ResponseData.success(page);
   }


    /**
     * 根据ID查询学生
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    @Operation(summary = "根据ID查询学生")
    @Parameter(name = "id",description = "学生ID",required = true)
    public ResponseData getById(@PathVariable("id") int id){
        Student stu=studentService.getById(id);
        return ResponseData.success(stu);
    }


    /**
     * 根据ID删除学生
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    @Operation(summary = "根据ID删除学生")
    @Parameter(name = "id",description = "学生ID",required = true)
    public ResponseData deleteById(@PathVariable("id") int id){
        boolean success=studentService.removeById(id);
        return ResponseData.success(success);
    }

    /**
     * 根据ID更新学生
     * @param id
     * @param stu
     * @return
     */
    @PutMapping("/updateById/{id}")
    @Operation(summary = "根据ID更新学生")
    @Parameter(name = "id",description = "学生ID",required = true)
    public ResponseData updateById(@PathVariable("id") int id,@Parameter(hidden = true) @RequestBody Student stu){
        boolean success=studentService.updateById(stu);
        return ResponseData.success(success);
    }

    /**
     * 新增学生
     * @param stu
     * @return
     */
    @PostMapping("/create")
    @Operation(summary = "新增学生")
    public ResponseData create(@Parameter(hidden = true) @RequestBody Student stu){
        boolean success=studentService.save(stu);
        return ResponseData.success(success);
    }

}